/*
 * Group 3, User Interface Programming II (vt11)
 * Pooya | Flora | Monica | Can
 */
package vical.action;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.KeyStroke;
import vical.model.Internationalization;
import vical.undo.UndoManager;
import vical.view.LeftPanel;
import vical.view.MainWindow;
import vical.view.ViewPanel;

/**
 * The Action to try to undo.
 * 
 * @author Can
 */
public class UndoAction extends AbstractAction {

    private UndoManager undoManager;
    private MainWindow mainWindow;

    private UndoAction() {
    }

    public UndoAction(UndoManager undoManager) {
        this(undoManager, null);
    }

    public UndoAction(UndoManager undoManager, MainWindow mainWindow) {
        super(Internationalization.getString("undo"));
        this.undoManager = undoManager;
        this.mainWindow = mainWindow;
        putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("control Z"));
    }

    public void actionPerformed(ActionEvent e) {
        undoManager.undo();
        if (mainWindow != null) {
            ((ViewPanel) mainWindow.getViewPanel()).refresh();
            ((LeftPanel) mainWindow.getLeftPanel()).refresh();
        }
    }
}
